<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUserCouponTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_coupon', function (Blueprint $table) {
            $table->id();
            $table->integer('userId', false, true)->index()->comment('用户id');
            $table->integer('couponId', false, true)->index()->comment('优惠券id');
            $table->integer('orderId', false, true)->index()->nullable()->comment('订单id');
            $table->dateTime('useAt')->nullable()->index()->comment('使用时间');
            $table->dateTime('getAt')->index()->comment('领取时间');
            $table->timestamps();
        });

        DB::statement("ALTER TABLE user_coupon comment '用户优惠券'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_coupon');
    }
}
